#ifndef PrintManager_First
#define PrintManager_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Dialog.h"

class PrintDialog;
class PrintPort;
class Printer;
class OrdCollection;
class Printer;
class PrintManager;

//---- PrinterSettings ------------------------------------------------------------

class PrinterSettings : public Object {
public:
	Point paperSize, topLeftMargin, bottomRightMargin;
	const char *name;
	bool showgrid;
public:
	MetaDef(PrinterSettings);
	PrinterSettings(Point ps, Point tlm, Point brm, Rectangle pr);
	~PrinterSettings();

	const char *GetName()
		{ return name; }
	void SetPaperSize(Point);
	Point GetPaperSize()
		{ return paperSize; }
	void SetTopLeftMargin(Point tlm);
	Point GetTopLeftMargin()
		{ return topLeftMargin; }
	void SetBottomRightMargin(Point brm);
	Point GetBottomRightMargin()
		{ return bottomRightMargin; }
	Rectangle GetPrintRect();
	Rectangle GetViewRect();
	void ShowPageBreaks(bool mode);
	bool GetShowPageBreaks()
		{ return showgrid; }
	Printer *GetPrinter();

	OStream& PrintOn(OStream&);
	IStream& ReadFrom(IStream&);
};

//---- PrintManager ------------------------------------------------------------

class PrintManager : public Object {
public:
	OrdCollection *printers;
	PrinterSettings *currSettings;
	Printer *currPrinter;
	VObject *vobject;

public:
	MetaDef(PrintManager);

	PrintManager();
	~PrintManager();

	void InstallPrinter(const char *name);

	Printer *PrinterAt(int no);
	int PrinterId(Printer*);

	void SetPaperSize(Point ps)
		{ currSettings->SetPaperSize(ps); }
	Point GetPaperSize()
		{ return currSettings->GetPaperSize(); }

	void SetTopLeftMargin(Point tlm)
		{ currSettings->SetTopLeftMargin(tlm); }
	Point GetTopLeftMargin()
		{ return currSettings->GetTopLeftMargin(); }

	void SetBottomRightMargin(Point brm)
		{ currSettings->SetBottomRightMargin(brm); }
	Point GetBottomRightMargin()
		{ return currSettings->GetBottomRightMargin(); }

	Rectangle GetPrintRect()
		{ return currSettings->GetPrintRect(); }
		
	Printer *GetPrinter()
		{ return currPrinter; }

	Rectangle GetViewRect()
		{ return currSettings->GetViewRect(); }

	void ShowPageBreaks(bool mode);
	bool GetShowPageBreaks(VObject *vop);

	Printer *FindPrinter(const char *name);

	virtual PrintDialog *MakePrintDialog();
	void Print(const char*, int from, int to);
	void ShowPageGrid(Rectangle r, VObject *);
	void ShowPrintDialog(VObject *v);
	virtual void PrintPage(int np, PrintPort *printport, Rectangle pgr);
};

//---- SmartPrintManager -------------------------------------------------------

class SmartPrintManager {
	PrintManager *pm;
public:
	SmartPrintManager()
		{ }
	~SmartPrintManager()
		{ SafeDelete(pm); }
	PrintManager *MakePrintManager();
	operator PrintManager* ()
		{ return MakePrintManager(); }
	PrintManager* operator-> ()
		{ return MakePrintManager(); }
};

extern SmartPrintManager gPrintManager;

extern bool gPrinting;

#endif

